package cn.sxt.userscenter.head.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.sxt.common.userscenter.util.ConstantFinalUtil;
import cn.sxt.userscenter.users.pojo.AUsers;

@Component("authInterceptor")
public class AuthInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		/* 验证是否登录 */
		HttpSession session = request.getSession();
		AUsers users = (AUsers) session.getAttribute("users");
		if(users == null){
			/* 未登录 跳转到登录页面 */
			session.setAttribute("info", ConstantFinalUtil.INFO_JSON.get("3"));
			response.sendRedirect(request.getContextPath() + "/login.htm");
			return false;
		}
		return true;
	}

}
